package com.ofek.applicationbase.forms;

import com.ofek.applicationbase.utils.Delegate;

import android.os.Bundle;

public class QuestionViewController {
	protected QuestionView question;
	
	public QuestionViewController(final QuestionView view) {
		question = view;
		question.registerAnswerChangedListener(new Delegate<Object>() {
			
			@Override
			public void invoke(Object t) {
				onAnswerChanged(t);
			}
		});
	}

	protected void onAnswerChanged(Object t) {}
	
	public boolean onSubmitRequested(boolean shouldAnimateIfInvalid) {
		boolean valid = question.hasValidInput();
		if (!valid && shouldAnimateIfInvalid) question.animateInvalidInput();
		return valid;
	}
	
	
	public QuestionView getQuestion() {
		return question;
	}

	public void setRequired(boolean required) {
		question.setRequired(required);
	}

	public boolean isRequired() {
		return question.isRequired();
	}

	public void setDefaultAnswer(final Object answer) {
		question.setAnswer(answer);
	}

	
}
